package com.wxw.BaseLibrary.component;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.wxw.BaseLibrary.drawable.PanelStyle;

/**
 *
 * @author david
 * @date 2014-06-06
 */
public class SimpleTextItemView extends LinearLayout {
    private TextView textView;
    private boolean hasBorder = false;
    private int verticalMargin = 10;

    public TextView getTextView() {
        return textView;
    }

    public boolean hasBorder() {
        return hasBorder;
    }

    public int getVerticalMargin() {
        return verticalMargin;
    }

    public void setVerticalMargin(int verticalMargin) {
        this.verticalMargin = verticalMargin;
        FrameLayout.LayoutParams layoutParams1 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        layoutParams1.setMargins(verticalMargin,verticalMargin,verticalMargin,verticalMargin);
        AbsListView.LayoutParams layoutParams2 = new AbsListView.LayoutParams(layoutParams1);
        setLayoutParams(layoutParams2);
    }

    public void setHasBorder(boolean hasBorder) {
        this.hasBorder = hasBorder;
        if (hasBorder) {
            textView.setBackground(PanelStyle.createWhitePanelStyle());
        } else {
            textView.setBackgroundColor(Color.TRANSPARENT);
        }
    }

    public SimpleTextItemView(Context context) {
        super(context);
        setBackgroundColor(Color.WHITE);
        LayoutParams layoutParams1 = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams1.setMargins(verticalMargin, verticalMargin, verticalMargin, verticalMargin);
        setLayoutParams(layoutParams1);
//        FrameLayout.LayoutParams layoutParams1 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
//                FrameLayout.LayoutParams.WRAP_CONTENT);
//        layoutParams1.setMargins(verticalMargin,verticalMargin,verticalMargin,verticalMargin);
//        AbsListView.LayoutParams layoutParams2 = new AbsListView.LayoutParams(layoutParams1);
//        setLayoutParams(layoutParams2);
        textView = new TextView(context);
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(5, verticalMargin, 5, verticalMargin);
        layoutParams.weight = 1;
        textView.setBackgroundColor(Color.TRANSPARENT);
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        addView(textView, layoutParams);
    }
}
